package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.mapper.WmMaterialMapper;
import com.heima.wemedia.service.WmMaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * author Link
 *
 * @version 1.0
 * @date 2025/4/6  16:37
 */
@RestController
@RequestMapping("/api/v1/material")
@Slf4j
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    @Autowired
    private WmMaterialMapper wmMaterialMapper;

    /**
     * 图片上传
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile){
        log.info("图片上传:{}", multipartFile);
        return wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 分页查询图片
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto){
        log.info("分页查询图片:{}", dto);
        return wmMaterialService.list(dto);
    }

    /**
     * 根据id删除素材
     * @param id
     */
    @GetMapping("/del_picture/{id}")
    public void deletePicture(@PathVariable Integer id){
        log.info("根据id删除素材：{}",id);
        wmMaterialMapper.deleteById(id);
    }
}


















